package com.miao.goods.service.impl;

import com.miao.commonn.utils.R;
import com.miao.goods.config.MD5Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.miao.commonn.utils.PageUtils;
import com.miao.commonn.utils.Query;

import com.miao.goods.dao.UserDao;
import com.miao.goods.entity.UserEntity;
import com.miao.goods.service.UserService;


@Service("userService")
public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements UserService {


    @Autowired
    UserDao userDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<UserEntity> page = this.page(
                new Query<UserEntity>().getPage(params),
                new QueryWrapper<UserEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public R regirant(UserEntity user) {

        UserEntity nickname = userDao.selectOne(new QueryWrapper<UserEntity>().eq("nickname", user.getNickname()));
        if (nickname==null){
            String s = MD5Util.md5Code(user.getPassword(), 2);

            user.setPassword(s);

            user.setRegisterData(new Date());
            user.setLoginCount(0);
            userDao.insert(user);
            return R.ok();
        }



        return R.error("用户名重复");

    }

}